package scalaoop

object GenericTest {
  /**
    * 泛型方法
    * 因为T是泛型，所以T不确定是否包含 comparTo 方法
    * T <: Comparable[T] 表示T必须是Comparable继承体系的一员,不认隐式转换的类型
    * T <% Comparable[T] 可以接收是隐式转换过来的类型
    */
  def Compare[T <% Comparable[T]](one:T,two:T):T={
    if(one.compareTo(two)>0) one else two
  }

  def main(args: Array[String]): Unit = {
    val s1=new Student(1,"huangbo")
    val s2 = new Student(2,"xuzheng")
    val result=Compare[Student](s1,s2)
    println(result)

  }
}
object Myimplict{
  //定义将dog转化为student的对象
  implicit def transfer1(d:Dog):Student=new Student(d.id,d.name)
}
//这是在继承体系的
class Student(val id:Int,val name:String) extends Comparable[Student]{
  //比较规则
  override def compareTo(o: Student) = {
    this.id-o.id
  }
}

class Dog(val id:Int,val name:String){}